<?php
class PageAction extends BaseAction{
	/**
	 * Show all stadic page
	 * Enter description here ...
	 */
	public function index(){
		$Page = M('Page');
		$pages = $Page->select();
		$this->assign('pages',$pages);
		$this->display();
	}
	/**
	 * Add a page
	 */
	public function add(){
		$Page = M("Page");
		$Page->create();
		$Page->page_content=str_replace(C('WWW'), "/",$Page->page_content);
		$isadd = $Page->add();
		if($isadd){
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->success('Succeed to add a new static page');
		}else {
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->error('Failed to add a new static page');
		}
	}
	/**
	 * Update a page
	 */
	public function update(){
		$Page = M("Page");
		$Page->create();
		$Page->page_content=str_replace(C('WWW'), "/",$Page->page_content);
		$issave = $Page->save();
		if($issave){
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->success('Succeed to Update a static page');
		}else {
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->error('Failed to Update this static page');
		}
	}
	/**
	 * Delete a page
	 */
	public function delete(){
		$Page = M("Page");
		if(isset($_GET['pageid']) && intval($_GET['pageid'])){
			$pageid= $_GET['pageid'];
			$isdel = $Page->where("page_id=".$pageid)->delete();
			if($isdel){
				$this->assign('waitSecond',15);
				$this->assign('jumpUrl','index');
			$this->success('Succeed to Delete a static page');
		}else {
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->error('Failed to Delete this static page');
		}
		}
		else{
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->error('请输入合法的参数');
		}
	}
	/**
	 * Html to add a page
	 * Enter description here ...
	 */
	public function addhtml(){
		$this->display();
	}
	/**
	 * Html to edit a page
	 * Enter description here ...
	 */
	public function edithtml(){
		$Page = M("Page");
		if(isset($_GET['pageid']) && intval($_GET['pageid'])){
			$pageid = $_GET['pageid'];
			$thispage = $Page->where('page_id='.$pageid)->find();
			$thispage['page_content']=str_replace("/Public",C('WWW')."Public",$thispage['page_content']);
			$this->assign('page',$thispage);
			$this->display();
		}
		else{
			$this->assign('waitSecond',15);
			$this->assign('jumpUrl','index');
			$this->error('请输入合法的参数');
		}
	}
}
?>